package com.kkarma.controller;

import com.kkarma.common.annotation.RateLimiter;
import com.kkarma.common.enums.RateLimiterEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: karma
 * @Date: 2022/5/25 0025 - 05 - 25 - 15:03
 * @Description: com.kkarma.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("/rate/limiter")
public class TestController {

    @GetMapping("test")
    @RateLimiter(time = 10, count = 3, limitType = RateLimiterEnum.IP)
    public String testRateLimiter() {
        return "rate limiter is valid at: " +
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }
}
